<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <link href="../../static/images/me.jpg" rel="icon" type="image/x-ico">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" type="text/css" href="../../static/css/myStyle.css">
</head>
<body>
    <!--导航栏-->
    <nav id="nav" th:replace="admin/_fragments :: menu(1)" class="ui inverted attached m-padded-tb-mini">
        <div class="ui container">
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui teal header item" style="font-family: STSong">后台管理</h2>
                <!--<div class="right m-item item m-mobile-hide">-->
                <a href="" class="m-item item m-mobile-hide"><i class="home icon"></i>博客</a>
                <a href="" class="m-item item m-mobile-hide"><i class="clone outline icon"></i>分类</a>
                <a href="" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
                <!--</div>-->
                <div class="right m-item m-mobile-hide menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img src="../../static/images/avatar.jpg" class="ui avatar image">
                            LENSTAR
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu m-opacity">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle button m-right-top m-mobile-show"
           style="background-color: rgba(0,0,0,0); color: gainsboro">
            <i class="sidebar icon"></i>
        </a>
    </nav>
    <div class="ui attached pointing menu m-opacity">
        <div class="ui container">
            <div class="right menu">
                <a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
                <a href="#" th:href="@{/admin/blogs}" class="teal active item">列表</a>
            </div>
        </div>
    </div>

    <br>
    <!--中间内容-->
    <div class="m-padded-tb-large m-container-small">
        <div class="ui container m-opacity">
            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${message}"></p>
            </div>

            <div  class="ui secondary segment form">
                <input type="hidden" name="page">
                <div class="inline fields">
                    <div class="field">
                        <input type="text" name="title" placeholder="标题">
                    </div>
                    <div class="field">
                        <div class="ui labeled action input">
                            <div class="ui type selection dropdown">
                                <input type="hidden" name="typeId">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">我的故事</div>
                                </div>
                            </div>
                            <button id="clear-btn" class="ui compact button">clear</button>
                        </div>

                    </div>
                    <div class="field">
                        <button type="button" id="query-btn" class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
                    </div>
                </div>
            </div>

            <div id="table-container">
                <table th:fragment="blogList" class="ui celled compact teal table">
                    <thead>
                    <tr align="center">
                        <th>序号</th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>状态</th>
                        <th>推荐</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr align="center" th:each="blog,iterStat : ${pageInfo.list}">
                        <td th:text="${iterStat.count}">1</td>
                        <td th:text="${blog.title}">刻意练习</td>
                        <td th:text="${blog.getType().name}">认知升级</td>
                        <td th:text="${blog.published} ? '草稿' : '发布'">草稿</td>
                        <td th:text="${blog.recommend} ? '是' : '否'">是</td>
                        <td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2020-08-01 17:52</td>
                        <td>
                            <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini teal basic button">编辑</a>
                            <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" onclick="return confirm('确定要删除该文章吗？三思啊! 删了可就没了！')" class="ui mini red basic button">删除</a>
                        </td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <th colspan="8">
                            <div class="ui mini pagination menu">
                                <a href="#" th:href="@{/admin/blogs(pageNum=${pageInfo.hasPreviousPage}? ${pageInfo.prePage} : 1)}" class="ui mini teal basic button item" style="margin-right: 0px;">上一页</a>
                                <a class="ui mini basic button item">第 <span th:text="${pageInfo.pageNum}"></span> 页，共 <span th:text="${pageInfo.pages}"></span> 页，有 <span th:text="${pageInfo.total}"></span> 篇文章</a>
                                <a href="#" th:href="@{/admin/blogs(pageNum=${pageInfo.hasNextPage}? ${pageInfo.nextPage} : ${pageInfo.pages})}" class="ui mini teal basic button item" style="margin-right: 0px;">下一页</a>
                            </div>
                            <a th:href="@{/admin/blogs/input}" class="ui mini right floated teal basic button">新增</a>
                        </th>
                    </tr>
                    </tfoot>
                </table>
            </div>

        </div>
    </div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>

    <!--底部栏-->
    <footer th:replace="admin/_fragments :: footer" class="ui inverted vertical m-padded-tb-massive">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid">
                <div class="four wide column">
                    <img src="../../static/images/wechat.jpg" alt="" style="width: 100px;">
                </div>
                <div class="four wide column">
                    <h4 class="ui inverted header m-text-spaced m-text-thin">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="" class="item">Java（User Story）</a>
                        <a href="" class="item">Linux（User Story）</a>
                        <a href="" class="item">Redis（User Story）</a>
                    </div>
                </div>
                <div class="four wide column">
                    <h4 class="ui inverted header m-text-spaced m-text-thin">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="" class="item">邮箱：XX181028@163.com</a>
                        <a href="" class="item">QQ：1412265423</a>
                    </div>
                </div>
                <div class="four wide column">
                    <h4 class="ui inverted header m-text-spaced m-text-thin">LENSTAR</h4>
                    <p class="m-text-spaced m-text-thin m-opacity-mini" style="color: gainsboro">
                        这是我的个人博客，会分享我所学到的任何知识，希望和大家一起共同进步.....
                    </p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-spaced m-text-thin m-opacity-mini" style="color: gainsboro">
                Copyright © 2020-2021 LENSTAR Designed by LENSTAR
            </p>
        </div>
    </footer>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
    <script>
        // 点击按钮触发事件
        $('.menu.toggle').click(function () {
            $('.m-item').toggleClass('m-mobile-hide');
        });

        //下拉框悬浮显示
        $('.ui.dropdown').dropdown({
            on: 'hover'
        });

        //关闭
        $('.message .close')
            .on('click', function () {
                $(this)
                    .closest('.message')
                    .transition('fade')
            });

        //清空搜索框的内容
        $('#clear-btn')
            .on('click', function() {
                $('.ui.type.dropdown')
                    .dropdown('clear')
                ;
            })
        ;

        //搜索博客
        $("#query-btn").click(function () {
            $("[name='page']").val(0);
            loaddata();
        });

        //ajax方法
        function loaddata() {
            $("#table-container").load(/*[[@{/admin/blogs/query}]]*/"/admin/blogs/query",{
                title : $("[name='title']").val(),
                typeId : $("[name='typeId']").val(),
                page : $("[name='page']").val()
            })
        }


    </script>
</body>
</html>